package cn.gzmli.dtt.common.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: jiangdw
 * @Date: 2020-03-31 10:20
 *
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true") //设置配置文件，是否启用swagger
public class SwaggerConfig {

	@Value("${swagger.basePackage}")
	private String basePackage;
	
	@Bean
	public Docket createRestApi() {
		//定义全局参数
//        List<Parameter> pars = new ArrayList<>();
//        ParameterBuilder token = new ParameterBuilder();
//        token.name("token").description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        pars.add(token.build());
		return new Docket(DocumentationType.SWAGGER_2)
				//.globalOperationParameters(pars) // 全局参数
				.groupName("PSS系统接口文档")//指定分组(用于父子模块项目的分组显示)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage(basePackage))
				.paths(PathSelectors.any())
				.build();
	}
	
	private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
				.title("Service API")
				.description("在线测试API接口文档")
				.version("1.0")
				.build();
	}


}
